package com.qf.service;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.FileNotFoundException;
import java.util.List;

/**
 * @author lixu
 * @Haha :  spring-context.xml
 *
 * <bean id="起名称" class="com.qf.service.UserServiceImpl"  init-method="abc()")></bean>
 */
//@Haha("起名称")
@Service //userService 默认就是叫userService
@Transactional // 全局的 整个类所有方法全加入事务
public class UserServiceImpl implements UserService {


    //声明
    /**
     * <bean id="起名称" class="com.qf.service.UserServiceImpl"  autowired=byType>
     * <property  name="userDao" ref="userDao"/> 手动注入
     * </bean>
     */
    @Autowired   //set注入： 默认是类型注入  类型注入失败 通过名称注入
    //@Qualifier(value = "uD")  //起名称   select id as idddddd from
    private UserDao userDao;


/*
    private UserDao userDao;


    public UserServiceImpl(@Autowired UserDao userDao) {
        this.userDao = userDao;
    }*/


    public List<User> findUser() {
        //Thread.sleep(10);//ms
        return userDao.findUser();
    }


    //保存  修改

    /**
     * 事务：
     *   @Transactional
     *       @Transactional(timeout = 5,
     *              propagation = Propagation.REQUIRES_NEW,
     *              isolation = Isolation.DEFAULT,rollbackFor = FileNotFoundException.class,
     *              rollbackForClassName = "java.io.FileNotFoundException",
     *              noRollbackFor = ArithmeticException.class,
     *               noRollbackForClassName = "",readOnly = true)
     * @param user
     */
   // @Transactional
    public void insertUser(User user) {

        userDao.insert(user);
        int i =1/0;

        userDao.update(user);
    }

    /**
     * 原始类：  房东
     * 代理类：  中介
     */

    @Override //Java1.5不技术  1.8支持
    @Transactional
    public String zufang(String name){
        System.out.println("我是参数:" + name);
        System.out.println("===我是房东、签合同");
        //int i = 1/0;
        System.out.println("===我是房东、收三押一");
        return "我是房东";
    }

}
